|
|
|
|
|
|
|
Figure 14.5.
An error message that asks for user input. |
|
|
|
|
|
|
|
|
When you need to force the program to return to a specific point in the routine, you can use the Resume label exit method. The Resume label method enables you to return to any place within the current procedure. You can't use Resume label to jump to another Sub or Function within the project. |
|
|
|
|
|
|
|
|
Now let's modify the BASICERR project to include an example of Resume label. Add a new command button to the project. Set its Name property to cmdResumeLabelErr and its Caption property to Resume Label. Now, place the code in Listing 14.7 behind the Click event. |
|
|
|
|
|
|
|
|
Listing 14.7. Using the Resume label keywords. |
|
|
|
|
|
|
|
|
Private Sub cmdResumeLabelErr_Click()
'
' show resume label version
'
On Error GoTo LocalErr
'
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
'
cmdLabelInput:
intX = InputBox("Enter a Divisor:", "Input Box #1")
intY = InputBox("Enter a Dividend:", "Input Box #2")
intZ = intX / intY
MsgBox "The Quotient is: " + Str(intZ), vbInformation, "Results"
GoTo LocalExit
'
LocalErr:
If Err = 11 Then ' divide by zero error
MsgBox CStr(Err.Number) & " - " & Err.Description, vbCritical,
"cmdResumeLabelErr"
Resume cmdLabelInput ' back for more |
|
|
|
|
|